<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
            <el-form-item label="拜访客户" prop="custVist">
                <el-input v-model="ruleForm.custVist" ></el-input>
            </el-form-item>
            <el-form-item label="拜访计划" prop="salePlan">
                <el-input  v-model="ruleForm.salePlan"></el-input>
            </el-form-item>
            <el-form-item label="客户需求" prop="demond">
                <el-input  v-model="ruleForm.demond"></el-input>
            </el-form-item>
            <el-form-item label="准备工作" prop="prepareWork">
                <el-input  v-model="ruleForm.prepareWork"></el-input>
            </el-form-item>
            <el-form-item label="拜访日期" prop="vistTime">
                <el-date-picker
                        v-model="ruleForm.vistTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
                </el-date-picker>
            </el-form-item>

        </el-form>
    </div>
</template>

<script>
    import {insertSalePlan}from '@/api/projectApi'
    export default {
        data() {
            return {
                ruleForm: {
                    custVist: '',
                    salePlan: '',
                    demond:'',
                    prepareWork: '',
                    probability: '',
                    vistTime:'',
                },
                rules: {
                    custVist: [
                        { required: true, message: '客户名称不可为空', trigger: 'blur' },
                    ],
                    salePlan: [
                        { required: true, message: '行动计划不可为空', trigger: 'blur' },
                    ],
                    vistTime: [
                        { required: true, message: '拜访日期不可为空', trigger: 'change' },
                    ],
                }
            };
        },
        methods: {
            //提交
            submit() {
                return new Promise((resolve, reject) => {
                    this.$refs['form'].validate((valid) => {
                        if(valid){
                            insertSalePlan(this.ruleForm).then(res => {
                                resolve(res.data)
                            }).catch(e => {
                                console.log(e,555)
                                reject(e)
                                this.$message.error({
                                    message: '抱歉，操作遇到异常，请重试或联系管理员处理'
                                })
                            })
                        }else {
                            this.$message.error('业务校验未通过')
                            reject(new Error('业务校验失败'))
                        }
                    })
                })

            }
        }
    }
</script>

<style scoped>

</style>
